package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IPermissionService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("permission")
public class PermissionController {

    @Autowired
    IPermissionService permissionService;

    @RequestMapping("")
    public String index(){

        return "permission/list";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(QueryObject qo){
        PageResult result = permissionService.query(qo);
        return result;
    }
    @RequestMapping("listData")
    @ResponseBody
    public Object listData(QueryObject qo){

        return permissionService.list();
    }

    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult result = new JSONResult();
        try{
            permissionService.delete(id);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }

    @RequestMapping("reload")
    @ResponseBody
    public JSONResult reload(){
        JSONResult result = new JSONResult();
        try{
            permissionService.reload();
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }
    @RequestMapping("getPermissionByRoleId")
    @ResponseBody
    public Object getPermissionByRoleId(Long id){
        return permissionService.getPermissionByRoleId(id);
    }
}
